package com.iot.service;

import com.iot.mapper.DTwork_statusMapper;
import com.iot.mapper.Twork_statusMapper;
import com.iot.pojo.MTwork_status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class Twork_statusServiceImpl implements Twork_statusService {
    @Autowired
    private Twork_statusMapper mapper;
    @Autowired
    private DTwork_statusMapper dmapper;
    @Override
    public int getRecordCount(String sWhere) {
        return mapper.getRecordCount(sWhere);
    }
    @Override
    public int insert(MTwork_status mTwork_status) throws Exception {

        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTwork_status.getSNAME() + "'");
        if (count > 0)
            throw new Exception("该名称已存在");
        return mapper.insert(mTwork_status);
    }

    @Override
    public void update(MTwork_status mTwork_status) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTwork_status.getSNAME() + "' AND WORK_STATUS_ID!=" + mTwork_status.getWORK_STATUS_ID() + "");
        if (count > 0)
            throw new Exception("该名称已存在");
        mapper.update(mTwork_status);
    }

    @Override
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @Override
    public MTwork_status single(Integer id) {
        return mapper.single(id);
    }

    @Override
    public List<MTwork_status> fetch(String sWhere) {
        return mapper.fetch(sWhere);
    }

    @Override
    public List<MTwork_status> fetchByPage(Map<String, Object> map) {

        return dmapper.fetchByPage(map);
    }


}
